package com.woniu.service.Impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.woniu.dao.CreditExamineNewDao;
import com.woniu.entity.CreAudit;
import com.woniu.entity.CreExamineNew;
import com.woniu.service.CreditExamineNewService;
import com.woniu.tool.ScoreCardUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CreditExamineNewServiceImpl implements CreditExamineNewService {
    @Autowired
    private CreditExamineNewDao creditExamineNewDao;

    @Autowired
    private ScoreCardUtil scoreCardUtil;
    /**
     * 查询
     *
     * @param examineId 主键
     * @return
     */
    @Override
    public CreExamineNew selectCreExamineNewByExamineId(Integer examineId)
    {
        return creditExamineNewDao.selectCreExamineNewByExamineId(examineId);
    }

    /**
     * 查询列表
     *
     * @param creExamineNew
     * @return
     */
    @Override
    public List<CreExamineNew> selectCreExamineNewList(CreExamineNew creExamineNew)
    {
        return creditExamineNewDao.selectCreExamineNewList(creExamineNew);
    }

    /**
     * 新增
     *
     * @param creExamineNew
     * @return 结果
     */
    @Override
    public int insertCreExamineNew(CreExamineNew creExamineNew)
    {
        if(creditExamineNewDao.selectCreExamineNewListCount(creExamineNew)>0){
            return -1;
        }
        return creditExamineNewDao.insertCreExamineNew(creExamineNew);
    }

    /**
     * 修改
     *
     * @param creExamineNew
     * @return 结果
     */
    @Override
    public int updateCreExamineNew(CreExamineNew creExamineNew)
    {
        return creditExamineNewDao.updateCreExamineNew(creExamineNew);
    }

    /**
     * 批量删除
     *
     * @param examineIds 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteCreExamineNewByExamineIds(Integer[] examineIds)
    {
        return creditExamineNewDao.deleteCreExamineNewByExamineIds(examineIds);
    }

    /**
     * 删除信息
     *
     * @param examineId 主键
     * @return 结果
     */
    @Override
    public int deleteCreExamineNewByExamineId(Integer examineId)
    {
        return creditExamineNewDao.deleteCreExamineNewByExamineId(examineId);
    }

    @Override
    public CreExamineNew selectCreExamineNewByOrderId(Integer orderId) {

        return creditExamineNewDao.selectCreExamineNewByOrderId(orderId);
    }

    @Override
    public CreAudit machineAudit(CreExamineNew creExamineNew) {
        Integer score = scoreCardUtil.getScore(creExamineNew);
        String advice = null;
        if(score>=0){
            advice="建议放贷";
        }else{
            advice="建议拒绝";
        }

        CreAudit creAudit = new CreAudit(score,advice);
        return creAudit;
    }

    @Override
    public String getUserName() {

        return SecurityUtils.getUsername();
    }
}
